<template>
  <page-layout>
    <div slot="toolbar">
      <el-button size="small" round type="primary" @click="newTeam">新增团队人员</el-button>
    </div>
    <div class="card-header">团队管理</div>
    <el-card class="box-card">
      <el-card class="box-card">
        <el-form ref="searchTeamCondition" :model="searchTeamCondition" label-width="80px" inline>
          <el-form-item label="标题">
            <el-input v-model="searchTeamCondition.title" style="width: 300px;"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="search(1)">查询</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <div class="flex-row">
        <div class="flex-item">
          <el-card class="box-card">
            <el-table
              :data="teamList.content" border stripe
              style="width: 100%">
              <el-table-column
                prop="id"
                label="编号"
                width="55">
              </el-table-column>
              <el-table-column prop="image" label="头像" width="210">
                <template slot-scope="scope">
                  <image-cover :thumb.sync="scope.row.image" width="187.5px" height="125px" size-type="contain"></image-cover>
                </template>
              </el-table-column>
              <el-table-column prop="name" label="姓名" ></el-table-column>
              <el-table-column
                prop="telphone"
                label="办公电话" width="150">
              </el-table-column>
              <el-table-column
                prop="departName"
                label="所属机构" width="120">
              </el-table-column>
              <el-table-column
                prop="duty"
                label="职务" width="120">
              </el-table-column>
              <el-table-column
                prop="introduction"
                label="简介" width="120">
                <template slot-scope="scope">
                  <span v-html="scope.row.introduction"></span>
                </template>
              </el-table-column>
              <el-table-column
                prop="visible"
                label="是否显示" width="100">
                <template slot-scope="scope">
                    {{scope.row.visible===true?"是":"否"}}
                </template>
              </el-table-column>
              <el-table-column label="操作" width="120">
                <template slot-scope="scope">
                  <el-button size="mini" @click="editTeam(scope.$index, scope.row)" type="text">编辑</el-button>
                  <!--<el-button size="mini" type="text" @click="preTeam(scope.row)">-->
                    <!--预览-->
                  <!--</el-button>-->
                  <el-button size="mini" type="text" @click="deleteTeam(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <div class="mt10">
              <el-pagination
                background
                layout="prev, pager, next"
                :total="teamList.totalElements"
                :page-size="teamList.size"
                :current-page.sync="currentTeamPage" @current-change="getPageChange">
              </el-pagination>
            </div>
          </el-card>
        </div>
      </div>
    </el-card>

    <el-dialog :visible.sync="showTeamEditor" title="添加/编辑 团队成员" width="80%">
      <team-editor @close="onTeamEditorClose" :is-close="showTeamEditor"></team-editor>
    </el-dialog>
    <el-dialog title="预览" :visible.sync="showPreview" width="50%">
      <pre-team @close="onShowPreviewClose" :is-close="showPreview"></pre-team>
    </el-dialog>
  </page-layout>
</template>
<script>
import PageLayout from "@/components/page-layout";
import TeamEditor from "./team-editor";
import PreTeam from "./pre-team";
import { mapGetters } from "vuex";
import ImageCover from "@/components/image-cover";
import Status from "@/libs/status";
export default {
  created() {
    this.$store.dispatch("getTeamPageS").then(ret => {});
  },
  mounted() {},
  data() {
    return {
      currentTeamPage: 1,
      showTeamEditor: false,
      showPreview: false,
      curPreObj: {},
      TeamStatus: Status.TeamStatus
    };
  },
  computed: {
    ...mapGetters({
      teamList: "teamList",
      searchTeamCondition: "searchTeamCondition"
    })
  },
  methods: {
    getPageChange(val) {
      var tem = Object.assign({ pageIndex: val - 1 }, this.searchTeamCondition);
      this.$store.dispatch("getTeamPageS", tem).then(ret => {});
    },
    search(val) {
      this.getPageChange(1);
    },
    deleteTeam(row) {
      this.$confirm("确认删除当前团队?", "提示", {})
        .then(() => {
          this.$store.dispatch("deleteTeamS", { id: row.id }).then(ret => {
            this.getPageChange(1);
            this.$notify({
              title: "删除成功",
              type: "success"
            });
          });
        })
        .catch(() => {});
    },
    preTeam(row) {
      this.$store.dispatch("getTeamS", row.id);
      this.showPreview = true;
    },
    newTeam() {
      this.$store.commit("INIT_CURRENT_TEAM");
      this.showTeamEditor = true;
    },
    editTeam(index, row) {
      this.$store.dispatch("getTeamS", row.id);
      this.showTeamEditor = true;
    },
    onTeamEditorClose() {
      this.showTeamEditor = false;
      this.getPageChange(1);
    },
    onShowPreviewClose() {
      this.showPreview = false;
      this.getPageChange(1);
    }
  },
  components: {
    PageLayout,
    TeamEditor,
    ImageCover,
    PreTeam
  }
};
</script>
<style>
</style>
